﻿using System;
using System.Collections.Generic;
using nRoute.Components;
using nRoute.Navigation.Mapping;
using nRoute.ViewModels;
using nRoute.Samples.OfficerXcel.Model;
using nRoute.Samples.OfficerXcel.Views;

namespace nRoute.Samples.OfficerXcel.ViewModels
{
    [DefineNavigationContent("Dialogs/NewDialog", typeof(NewDialog))]
    [MapViewModel(typeof(NewDialog))]
    public class NewDialogViewModel
        : NavigationViewModelBase
    {
        public NewDialogViewModel()
        {
            SetupTemplates();
            SetupCommands();
        }

#region Properties

        public List<DocumentTemplate> LocalDocumentTemplates { get; private set; }

        public List<DocumentTemplate> OnlineDocumentTemplates { get; private set; }

        public ActionCommand LocalTemplateSelectionCommand { get; private set; }

        public ActionCommand OnlineTemplateSelectionCommand { get; private set; }

        public DocumentTemplate ActiveTemplate {get; private set; }

        public DocumentTemplate LocalSelectedTemplate { get; set; }

        public DocumentTemplate OnlineSelectedTemplate { get; set; }

#endregion

#region Helpers

        private void SetupTemplates()
        {
            LocalDocumentTemplates = DocumentTemplatesManager.GetLocalTemplates();
            OnlineDocumentTemplates = DocumentTemplatesManager.GetOnlineTemplates();
        }

        private void SetupCommands()
        {
            LocalTemplateSelectionCommand = new ActionCommand(() =>
            {
                if (LocalSelectedTemplate != null)
                {
                    ActiveTemplate = LocalSelectedTemplate;
                    OnlineSelectedTemplate = null;
                    NotifyPropertyChanged(() => OnlineSelectedTemplate);
                    NotifyPropertyChanged(() => ActiveTemplate);
                }
            });

            OnlineTemplateSelectionCommand = new ActionCommand(() =>
            {
                if (OnlineSelectedTemplate != null)
                {
                    ActiveTemplate = OnlineSelectedTemplate;
                    LocalSelectedTemplate = null;
                    NotifyPropertyChanged(() => LocalSelectedTemplate);
                    NotifyPropertyChanged(() => ActiveTemplate);
                }
            });
        }

#endregion

    }
}